<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>注册</title>

    <link rel="stylesheet" href="../css/page-health-login.css" />
    <script src="/js/vue.js"></script>
    <script src="/js/axios-0.18.0.js"></script>
</head>

<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<div class="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><i class="icon-back"></i>返回</span>
        <span class="center">注册界面</span>
        <span class="f-right"><i class="icon-more"></i></span>
    </div>
    <!-- 页面内容 -->
    <div class="contentBox">
        <div class="login">
            <form id='login-form' class="input-group">
                <div class="input-row">
                    <label>请输入用户名</label>
                    <input id='account' v-model="user.username" type="text" class="input-clear input" placeholder="请输入用户名">
                </div>
                <div class="input-row">
                    <label>设置登录密码</label>
                    <input id='password' v-model="user.password" type="password" class="input-clear input" placeholder="请输入密码">
                </div>
                <div class="input-row">
                    <label>校验登录密码</label>
                    <input id='password2' v-model="user.password2" type="password" class="input-clear input" placeholder="请再次输入密码">
                </div>
                <div class="btn yes-btn"><a @click="regist(user.password,user.password2)">注册</a></div>
                <div class="btn yes-btn"><a href="health-login.html" style="color: red">已有账户！前往登录</a></div>
                <div class="btn cancel-btn">取消</div>
            </form>
        </div>
    </div>
</div>
<!-- 页面 css js -->


</body>
<script src="/js/vue.js"></script>
<script src="/js/axios-0.18.0.js"></script>
<script src="/plugins/uedter/third-party/jquery-1.10.2.js"></script>
<script>

    new Vue({
        el:".app",
        data:{
            user: {
                username: "",
                password: "",
                password2: ""
            }
        },
        methods:{
            regist(password,password2) {
                if (password === password2) {
                    axios.defaults.withCredentials = true;
                    axios({
                        url: "http://localhost/register",
                        method: "post",
                        data: this.user
                    }).then(resp => {
                        let result = resp.data;
                        if (result.code === 1000) {
                            alert(resp.data.data)
                            window.location.href = "/health-login.html";
                        } else if (result.code === 3000) {
                            alert(result.msg)
                            window.location.href = "/health-login.html";
                        }
                    });
                } else {
                    alert("两次密码输入不一致，请重新校对！")
                }
            }
        }
    });
</script>

</html>